<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="HandheldFriendly" content="true" />
		<meta name="MobileOptimized" content="320" />
		<title>材料管理</title>

		<style type="text/css">
			.fitem {
				width: 96%;
				overflow: hidden;
				padding: 10px 2%;
				border-bottom: 1px solid #c6c6c6;
				color: #6c6c6c;
				text-align: left;
				text-decoration: none;
				display: block;
			}
			
			.fitem:active {
				background: #f4f4f4;
			}
			
			.fname {
				font-weight: bolder;
				height: 22px;
				font-size: 16px;
			}
			
			.iclear {
				background: no-repeat center center url();
				background-size: 50px 44px;
			}
			
			styles: {
				top: 0, bottom: 0, hardwareAccelerated: true, //开启硬件加速
				scrollIndicator: 'none'
			}
		</style>
		<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" onclick="back(true);"></a>

			<a class="mui-tab-item" href="#forward">
				<span class="mui-icon mui-icon-list mui-icon-right-nav mui-pull-right"></span>
			</a>
			<h1 class="mui-title">详情</h1>

		</header>
		<!--<header id="header">
			<div class="nvbt iback" onclick="resetUploader();back();"></div>
			<div class="nvtt">Uploaded Data&amp;File</div>
			<div class="nvbt iclear" onclick="deleteFiles()"></div>
		</header>-->
		<div id="dcontent" class="dcontent">
			<br />
			<p class="heading">名称：</p>
			<div class="mui-input-row" style="margin: 15px 15px;">
				<input type="text" readonly="true" id="mname">
			</div>
			<p class="heading">图片描述：</p>
			<div class="mui-input-row" style="margin: 15px 15px;">

				<textarea id="otherinfo" readonly="true" rows="3"></textarea>
			</div>

			<p class="heading">图片列表：</p>
			<div class="imgcontent">
				<!--这里放图片-->
			</div>

		</div>
		<div id="forward" class="mui-popover mui-popover-action mui-popover-bottom">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell" type="audit" id="btnaudit">
					审核通过
				</li>
				<li class="mui-table-view-cell" type="unaudit" id="btnunaudit">
					驳回
				</li>
				<li class="mui-table-view-cell" type="delete" id="btndelete">
					删除
				</li>
			</ul>

			<ul class="mui-table-view">
				<li class="mui-table-view-cell">
					<a href="#forward"><b>取消</b></a>
				</li>
			</ul>
		</div>
	</body>
	<script type="text/javascript" src="../js/immersed.js"></script>

</html>
<script type="text/javascript" src="../js/common.js"></script>
<script src="../js/mui.min.js"></script>
<script src="../js/wf.js"></script>
<script src="../js/zepto.min.js"></script>
<script src="../js/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script src="../js/mui.zoom.js"></script>
<script src="../js/mui.previewimage.js"></script>
<script type="text/javascript">
	(function(doc) {
		mui.init();
		mui.previewImage();
		mui.plusReady(function() {
			var datas = new Object();
			var picarr = new Object();
			var self = plus.webview.currentWebview();
			var username = self.username;
			datas.proid = self.proid;
			datas.mid = self.mid;
			datas.value = self.value;
			//datas.username=username;
			plus.nativeUI.showWaiting();
			wf.ajax("Material/MaterialDetail", {
				traditional: true,
				type: "post",
				data: datas,
				dataType: "json",
				success: function(resule) {

					if(resule.Code == "40001") {
						var word = JSON.parse(resule.Data);
						$("#mname").val(word.MName);
						$("#otherinfo").val(word.MDes);
					} else if(resule.Code == "20000") {
						//显示文字
						var word = JSON.parse(resule.Msg);

						$("#mname").val(word.MName);
						$("#otherinfo").val(word.MDes);
						//显示图片
						picarr = JSON.parse(resule.Data);

						if(picarr.length > 0) {
							for(var i = 0; i < picarr.length; i++) {
								showImg(picarr[i].FileEntity, i);

							}
						}

					} else {

						mui.toast(resule.Msg);
					}

					plus.nativeUI.closeWaiting();
				}
			});

			//这里写方法
			//审核
			$("#btnaudit").on("tap", function() {
				var a = this,
					parent;
				var table = document.body.querySelector('.mui-table-view');
				table.getElementsByTagName("li")[0].style.display = "none";
				table.getElementsByTagName("li")[1].style.display = "";

				//根据点击按钮，反推当前是哪个actionsheet
				for(parent = a.parentNode; parent != document.body; parent = parent.parentNode) {
					if(parent.classList.contains('mui-popover-action')) {
						break;
					}
				}
				datas.AuditPeople = username;
				wf.ajax("Material/MaterialAudit", {
					traditional: true,
					type: "post",
					data: datas,
					dataType: "json",
					success: function(resule) {
						if(resule.Code = "20000") {
							mui.toast(resule.Msg);
							mui('#' + parent.id).popover('toggle');
							refreshParent();
						} else {
							mui.toast(resule.Msg);
						}
					}
				});
			});
			//驳回	
			$("#btnunaudit").on("tap", function() {
				var a = this,
					parent;
				var table = document.body.querySelector('.mui-table-view');
				table.getElementsByTagName("li")[1].style.display = "none";
				table.getElementsByTagName("li")[0].style.display = "";

				//根据点击按钮，反推当前是哪个actionsheet
				for(parent = a.parentNode; parent != document.body; parent = parent.parentNode) {
					if(parent.classList.contains('mui-popover-action')) {
						break;
					}
				}
				datas.AuditPeople = username;
				wf.ajax("Material/MaterialUnAudit", {
					traditional: true,
					type: "post",
					data: datas,
					dataType: "json",
					success: function(resule) {
						if(resule.Code = "20000") {
							mui.toast(resule.Msg);
							mui('#' + parent.id).popover('toggle');
							refreshParent();
						} else {
							mui.toast(resule.Msg);
						}
					}
				});
			});
			//删除
			$("#btndelete").on("tap", function() {
				var a = this,
					parent;
				var table = document.body.querySelector('.mui-table-view');
				//				table.getElementsByTagName("li")[0].style.display = "none";
				//				table.getElementsByTagName("li")[1].style.display = "";

				//根据点击按钮，反推当前是哪个actionsheet
				for(parent = a.parentNode; parent != document.body; parent = parent.parentNode) {
					if(parent.classList.contains('mui-popover-action')) {
						break;
					}
				}
				datas.AuditPeople = username;
				wf.ajax("Material/MaterialDelete", {
					traditional: true,
					type: "post",
					data: datas,
					dataType: "json",
					success: function(resule) {
						if(resule.Code = "20000") {
							mui.toast(resule.Msg);
							mui('#' + parent.id).popover('toggle');
							refreshParent();
						} else {
							mui.toast(resule.Msg);
						}
					}
				});
			});
			//删除
			//			$("#btndelete").on("tap", function() {
			//				var btnArray = ['否', '是'];
			//				mui.confirm('删除所有内容将无法恢复,确认？', 'Hello MUI', btnArray, function(e) {
			//					if (e.index == 1) {
			//						wf.ajax("Material/MaterialDelete", {
			//							traditional: true,
			//							type: "post",
			//							data: datas,
			//							dataType: "json",
			//							success: function(resule) {
			//								if (resule.Code = "20000") {
			//									mui.toast(resule.Msg);
			//									mui('#' + parent.id).popover('toggle');
			//									refreshParent();
			//								}
			//							}
			//						});
			//
			//					} else {
			//						mui.toast('你们放弃了删除');
			//					}
			//				});
			//			});
			//------------------------------

		});
	}(document));

	// H5 plus事件处理

	function refreshParent() {

		var main = plus.webview.getWebviewById('materiallistsub'); //或者通过A页面id获取A页面对象

		main.reload(true);
		back(true);

	}

	function showImg(Data, i) {
		var _img_ = new Image();
		_img_.style.border = "1px solid rgb(200,199,204)";
		_img_.style.margin = "10px";
		_img_.style.width = "90%";
//		_img_.style.height = "200px";
		_img_.src = Data;
		_img_.id = i;
		var div = document.getElementsByClassName("imgcontent")[0];
		div.appendChild(_img_);
		$("#" + i).attr("data-preview-src", "");
		$("#" + i).attr("data-preview-group", 1);
	}
</script>